﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jzy.Model.Mail;
using Frame.Lib.Core.Log;
using Frame.Lib.Core.Dispatch;


namespace Jzy.BLL.Mail
{
    public class WebMailDispatch:IDispatch
    {
        private static int _errorCount;
        private static DateTime _errorTime;

        public WebMailDispatch() { }


        public void Run()
        {
            List<WebMailAccountInfo> accountList = WebMailAccountBO.GetAllList();

            foreach (WebMailAccountInfo info in accountList)
            {
                try
                {
                    WebMailBO.Receive(info);
                }
                catch (Exception ex)
                {
                    if (DateTime.Now.Date != _errorTime.Date)
                    {
                        _errorTime = DateTime.Now;
                        _errorCount = 0;
                    }
                    if (_errorCount < 100)
                    {
                        Logger.Exception(ex, "Receive Mail Error");
                    }
                }
                
            }
        }
    }
}
